package cn.schoolwow.flow.monitor.test.config;

import cn.schoolwow.flow.monitor.domain.FlowMonitorOption;
import cn.schoolwow.quickdao.QuickDAO;
import cn.schoolwow.quickdao.domain.DAO;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DAOConfig {
    @Bean
    public HikariDataSource mysqlDataSource(){
        HikariDataSource hikariDataSource = new HikariDataSource();
        hikariDataSource.setDriverClassName("com.mysql.jdbc.Driver");
        hikariDataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/flow_monitor?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
        hikariDataSource.setUsername("root");
        hikariDataSource.setPassword("123456");
        return hikariDataSource;
    }

    @Bean(name = "starterDAO")
    @Autowired
    public DAO starterDAO(HikariDataSource hikariDataSource) {
        QuickDAO quickDAO = QuickDAO.newInstance()
                .dataSource(hikariDataSource)
                .packageName("cn.schoolwow.flow.monitor.test.entity");
        FlowMonitorOption.initialQuickDAO(quickDAO);
        DAO starterDAO = quickDAO.build();
        return starterDAO;
    }
}
